var num = [2, 7, 11, 15], target = 13

var twoSum = function (nums, target) {
    var diff = {}

    for (var i = 0; i < nums.length; i++) {
        if (diff[nums[i]] !== undefined) {  // 查找对象中是否存在值，是不需要循环的
            return [diff[nums[i]], i]
        }
        diff[target - nums[i]] = i
    }

};